package com.osce.basic.controller;

import com.csce.domain.entity.basic.BasicSchool;
import com.osce.common.annotation.Log;
import com.osce.common.core.controller.BaseController;
import com.osce.common.core.entity.AjaxResult;
import com.osce.common.core.page.TableDataInfo;
import com.osce.common.enums.BusinessType;
import com.osce.common.utils.poi.ExcelUtil;
import com.osce.interfaces.basic.IBasicSchoolService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 学校表Controller
 *
 * @author zzx
 * @since 2023-07-18
 */
@RestController
@RequestMapping("/basic/school")
public class BasicSchoolController extends BaseController {

    @Resource
    private IBasicSchoolService basicSchoolService;

    /**
     * 查询学校表列表
     */
    @PreAuthorize("@ss.hasPermi('basic:school:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicSchool basicSchool) {
        startPage();
        List<BasicSchool> list = basicSchoolService.selectBasicSchoolList(basicSchool);
        return getDataTable(list);
    }

    /**
     * 导出学校表列表
     */
    @PreAuthorize("@ss.hasPermi('basic:school:export')")
    @Log(title = "学校表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasicSchool basicSchool) {
        List<BasicSchool> list = basicSchoolService.selectBasicSchoolList(basicSchool);
        ExcelUtil<BasicSchool> util = new ExcelUtil<BasicSchool>(BasicSchool.class);
        util.exportExcel(response, list, "学校表数据");
    }

    /**
     * 获取学校表详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:school:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(basicSchoolService.selectBasicSchoolById(id));
    }

    /**
     * 新增学校表
     */
    @PreAuthorize("@ss.hasPermi('basic:school:add')")
    @Log(title = "学校表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicSchool basicSchool) {
        return toAjax(basicSchoolService.insertBasicSchool(basicSchool));
    }

    /**
     * 修改学校表
     */
    @PreAuthorize("@ss.hasPermi('basic:school:edit')")
    @Log(title = "学校表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicSchool basicSchool) {
        return toAjax(basicSchoolService.updateBasicSchool(basicSchool));
    }

    /**
     * 删除学校表
     */
    @PreAuthorize("@ss.hasPermi('basic:school:remove')")
    @Log(title = "学校表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(basicSchoolService.deleteBasicSchoolByIds(ids));
    }
}
